package com.ywjt.platformbusiness.store.adapter;

import android.graphics.Color;
import android.view.animation.LinearInterpolator;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ywjt.platformbusiness.R;
import com.ywjt.platformbusiness.store.model.BusinessMessageModel;

import java.util.List;

import me.samlss.broccoli.Broccoli;
import me.samlss.broccoli.BroccoliGradientDrawable;
import me.samlss.broccoli.PlaceholderParameter;

public class BusinessCenterMessageAdapter extends BaseQuickAdapter<BusinessMessageModel.ResultDTO, BaseViewHolder> {

    public BusinessCenterMessageAdapter(@Nullable List<BusinessMessageModel.ResultDTO> data) {
        super(R.layout.item_message, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, BusinessMessageModel.ResultDTO item) {
        Broccoli broccoli = null;
        if (broccoli == null){
            broccoli = new Broccoli();
        }

        broccoli.removeAllPlaceholders();
        broccoli.addPlaceholder(new PlaceholderParameter.Builder()
                .setView(helper.getView(R.id.tvCreateTime))
                .setDrawable(new BroccoliGradientDrawable(Color.parseColor("#DDDDDD"),
                        Color.parseColor("#CCCCCC"), 0, 1000, new LinearInterpolator()))
                .build());
        broccoli.addPlaceholder(new PlaceholderParameter.Builder()
                .setView(helper.getView(R.id.tvContent))
                .setDrawable(new BroccoliGradientDrawable(Color.parseColor("#DDDDDD"),
                        Color.parseColor("#CCCCCC"), 0, 1000, new LinearInterpolator()))
                .build());
        broccoli.show();



        Runnable task = null;
        if (task == null){
            final Broccoli finalBroccoli = broccoli;
            task = new Runnable() {
                @Override
                public void run() {
                    //when you need to update data, you must to call the remove or the clear method.
                    finalBroccoli.removeAllPlaceholders();

                    if (item==null){
                        return;
                    }
                    helper.setText(R.id.tvCreateTime,item.getCreateTime());
                    helper.setText(R.id.tvContent,item.getContent());
                }
            };
        }else{
            helper.itemView.removeCallbacks(task);
        }
        helper.itemView.postDelayed(task, 1000);
    }
}
